define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";
	
    var self = exports;
    var utils = require('mokit/utils');
    var service = require('./service');
    var user = require('./User');
	
	self.type = "provider";
	self.imgPath = user.syproUri;
	
	/*===========服务商列表==========*/
	
	self.list =  [];
	self.args = {
		serviceType:"sel",
		level:"sel",
		authentication:"sel",
		category: "sel",
		page: 1,
		pageSize: 5
	};
	self.isEnd = false;
	self.sortBy = "level";
	self.sortDir = "desc";
	
	//重置列表
	self.resetList = function(){
		this.list = [];
		this.args.page = 1;
		this.isEnd = false;
	};
	
     //初始化列表
	self.iniList = function(callback){
    	this.resetList();     	
     	this.getList(callback);
	};
	
    //排序列表
    self.sortList = function(sortBy, callback){
     	this.sortDir = this.sortBy==sortBy ? (this.sortDir=="asc"?"desc":"asc") : "desc";
     	this.sortBy = sortBy;
		this.iniList(callback);
    };

    //筛选列表
    self.filterList = function(type, val, callback){
     	this.args[type] = val;
		this.iniList(callback);
    };
    
    //加载更多列表
	self.loadMoreList = function(callback){
		if(!this.isEnd){
			this.args.page++;
			this.getList(callback);
		}
	};
	
    //获取列表
	self.getList = function(callback){
        service.provider.getList(this.args, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
               	self.list = self.list.concat(rs.obj);
               	self.isEnd = rs.obj.length<self.args.pageSize;
               	var isEmpty = self.args.page>1 && rs.obj.length==0;
                if (callback) callback(!isEmpty);
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        });    	
    };
	    
	/*===========服务商详情==========*/

	self.id = 0;
	self.info =  {};
	
    //获取详情
	self.getInfo = function(id, callback){
		this.providerId = id;
        service.provider.getInfo({id:id}, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
               	self.info = rs.obj;
                if (callback) callback();
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        });    	
    };

    //推荐
	self.tuijian = function(callback){
        service.provider.tuijian({id:this.providerId}, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
                if (callback) callback();
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        }); 		
	};

    //邀请加入团队
	self.joinTeam = function(callback){
        service.provider.joinTeam({id:this.providerId}, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
                if (callback) callback();
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        }); 		
	};
	
    //关注
	self.attention= function(callback){
        service.provider.attention({id:this.providerId}, function(rs, err) {
            if (err && callback) return callback(err.message || err);
            if (rs.success) {
                if (callback) callback();
            } else {
                rs = rs || {};
                var msg = rs.msg || 'unknow error';
                if (callback) callback(msg);
            }
        }); 			
	};

	self.wallArgs = {
		userid: user.state.userId,
		serviceType:"sel",
		level:"sel",
		authentication:"sel",
		category: "sel",
		pageNo: 0,
		pageSize: 4,	
	};
});